package gs

import (
	"brickyard/coordinator"
	. "brickyard/share"
	. "brickyard/util"
	"errors"
)

type Gateway struct {
	coord *coordinator.Clerk
	fsm   *fsmaster.Clerk
}

func NewServer() *Gateway {
	return new(Gateway)
}

func (g *Gateway) Shutdown() {}

func (g *Gateway) Start(cfgfile string) error {
	config := LoadConfigFile(cfgfile)

	coordServer := config.GetString("coordinator")
	if coordServer == "" {
		return errors.New("Config file without coordinator")
	}

	clusterName := config.GetString("cluster")
	g.coord = coord.Dial(coordServer, clusterName)
	if g.coord == nil {
		return errors.New("Failed to dail to coordinator")
	}

	return nil
}
